package com.example.gbb;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;

import com.example.gbb.adapters.MoreTypeAdapter;
import com.example.gbb.bean.Datas;
import com.example.gbb.bean.MoreTypeBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Main2Activity extends AppCompatActivity {
    private static final String TAG = "Main2Activity";
    private RecyclerView recyclerView;
    private List<MoreTypeBean> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //绑定控件
        initView();

        //准备数据
        initData();

        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);

        //创建适配器
        MoreTypeAdapter moreTypeAdapter= new MoreTypeAdapter(list);

        //绑定适配器
        recyclerView.setAdapter(moreTypeAdapter);
    }

    private void initData() {
        //获取随机数对象
        Random random = new Random();

        list = new ArrayList<>();
        for(int i = 0;i < Datas.icons.length;i++){
            MoreTypeBean moreTypeBean = new MoreTypeBean();
            moreTypeBean.pic = Datas.icons[i];

            //获取一个等于0到小于3之间的随机数并且赋值给type
            moreTypeBean.type = random.nextInt(3);
            Log.d(TAG,"type----------------------->"+moreTypeBean.type);

            list.add(moreTypeBean);
        }

    }

    private void initView() {
        recyclerView = this.findViewById(R.id.more_type_list);
    }
}
